package com.android.app.aqcon;

import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;


import android.app.Activity;
import android.content.Context;
import android.media.AudioManager;
import android.net.rtp.AudioCodec;
import android.net.rtp.AudioGroup;
import android.net.rtp.AudioStream;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

public class AQCONLogin extends Activity {
    /** Called when the activity is first created. */
	
	private AudioStream stream;
    private AudioGroup group;
    private int peerPort;
	private TextView view_status;
	private Button button_connect;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        //findView();
        
        
        try {
			stream = new AudioStream(InetAddress.getByName("127.0.0.1"));
			//System.out.println(InetAddress.getByName("127.0.0.1"));
		} catch (SocketException e) {
			// TODO Auto-generated catch block
			//view_status.setText("socket problem");
			e.printStackTrace();
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			//view_status.setText("host problem");
			e.printStackTrace();
		}
        
        
		try {
			InetAddress addr;
			addr = InetAddress.getByName("192.168.1.5");
			peerPort = 16403;
			
			AudioManager audiomanager = (AudioManager)this.getSystemService(Context.AUDIO_SERVICE);
			audiomanager.setMode(AudioManager.MODE_IN_COMMUNICATION);
			
			stream.setMode(AudioStream.MODE_NORMAL);
			stream.setCodec(AudioCodec.GSM);
	        stream.associate(addr, peerPort);
	        //stream.setDtmfType(3);
	        group = new AudioGroup();
	        stream.join(group);
	        group.setMode(AudioGroup.MODE_NORMAL);
	        
	        
		} catch (UnknownHostException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
        
    }
    
    @Override
	protected void onDestroy() {
		super.onDestroy();
		android.os.Process.killProcess(android.os.Process.myPid());
	}

	/*private void findView(){
		view_status = (TextView)findViewById(R.id.view_status);
		button_connect = (Button)findViewById(R.id.button1);
	}*/
	
	
}